#sing @echo off & SetLocal EnableDelayedExpansion & del "#pathlog.txt" & cd /d "#ppthapps\mencoder"
#newl#sing set maxw=512|#newl#sing set maxw=480|--Fallback width. There is no space at the end.--
#newl set audionew=-oac twolame -twolameopts br=128|#newl set audionew=-oac mp3lame -lameopts cbr:br=128|#newl set audionew=-oac twolame -twolameopts br=64 -af channels=1|#newl set audionew=-of lavf -oac lavc -lavcopts acodec=mp2:abitrate=128|#newl set audionew=-of lavf -oac lavc -lavcopts acodec=mp2:abitrate=64 -af channels=1|--Fallback audio codec--
#newl FOR /F "tokens=1,2 delims==" %%G IN ('mplayer.exe -identify -frames 0 -vo null -ao null  "#item" ') DO ( 
#newl IF %%G==ID_AUDIO_FORMAT IF %%H==85 (set encodemp3=-oac copy& set audio_codec=%%H) else (set encodemp3=!audionew!& set audio_codec=not_mp3) )
#newl if !ID_VIDEO_WIDTH! leq !maxw!  (set resizeline=) else (set resizeline=-vf scale -zoom -xy !maxw!)
#newl IF #exte==.flv (set encodemp3=!audionew!& set audio_codec=.flv, overriding, set to encode audio)
#newl echo old size="!ID_VIDEO_WIDTH!:!ID_VIDEO_HEIGHT!" new size="!maxw!:auto",  audio_codec="!audio_codec!" & echo *** resizeline="!resizeline!" encodemp3="!encodemp3!"
#newl "#ppthapps\mencoder\mencoder.exe" |--Path to file--
"#item" |--input file--
-ovc lavc -lavcopts vcodec=mpeg4:threads=2:vqscale=3.33 |-ovc lavc -lavcopts vcodec=mpeg4:threads=2:vbitrate=500 |-ovc lavc -lavcopts vcodec=mpeg4:threads=2:vbitrate=1000 |-ovc xvid -xvidencopts threads=2:bitrate=1000 |-ovc xvid -xvidencopts fixed_quant=3.33:threads=2 |-ovc xvid -xvidencopts pass=1:threads=2 |-ovc xvid -fixed_quant=3.33:threads=2:vhq=4 |--Video encoder--
!resizeline! |-vf scale -zoom -xy 512 |-vf scale -zoom -xy 480 |-vf scale=480:-3 |-vf scale=480:-2 |-resize, !! means use (resulting) variable-
#remark -scaling type-|-sws 0 |--scaling type--
!encodemp3! |-oac twolame -twolameopts br=128 |-oac twolame -twolameopts br=64 -af channels=1 |-oac mp3lame -lameopts cbr:br=128 |-of lavf -oac lavc -lavcopts acodec=mp2:abitrate=128 |-of lavf -oac lavc -lavcopts acodec=mp2:abitrate=64 -af channels=1 |-oac pcm |-oac copy |--audio encoder, !! means use (resulting) variable--
#remark -channels-|-af channels=1 |-af channels=2 |-channels-
-ffourcc XVID |-ffourcc DIVX |-ffourcc AVC1 |--Video tag. Use AVC1 for GoClever, instead of x264--
#remark -start time-|-ss 00:02:40 |-ss 49 |--Start time. Optional. HH:MM:SS--
#remark -end time-|-endpos 30 |-endpos 00:00:60 |--End time. Optional. Added to start time--
-o "#path#name-menc.avi" |--output file--
#remark -resample audio-|-af resample=44100 |-af resample=22050 |--resample audio--
#remark -set framerate-|-fps 25 |-fps 24 |-fps 23.97 |-fps 29.97 |-fps 30 |-fps 24000/1001 |--output fps--
#remark -aspect ratio-|-aspect 16:9 |-aspect 16:10 |-aspect 4:3 |--aspect ratio--
#remark -burn subtitle to file-|-sub "#path#name.srt" |-sub "#path#name.srt" -sid 999 |--burn subtitle to file, sid 999 to disable mkv subtitles--
#remark -subtitle encoding-|-subcp cp1250 |--subtitle encoding--
#remark -subtitle font size-|-subfont-text-scale 4.1 |--subtitle font size, default 4?--
#remark -move the subtitles up a bit-|-subpos 96 |--move the subtitles up a bit--
#newl set oldLength=!ID_LENGTH!
#newl FOR /F "tokens=1,2 delims==" %%G IN ('mplayer.exe -identify -frames 0 -vo null -ao null  "#path#name-menc.avi" ') DO ( set %%G=%%H)
#newl set newLength=!ID_LENGTH!& echo old length:!oldLength!, new length:!newLength!.
#newl IF !newLength!==!oldLength! (echo old length:!oldLength!, new length:!newLength! "#item" resizeline="!resizeline!" encodemp3="!encodemp3!" >> "#pathlog.txt") ELSE (echo WARNING: old length:!oldLength!, new length:!newLength! "#item" resizeline="!resizeline!" encodemp3="!encodemp3!">> "#pathlog.txt")


rem Use cd to dir first, cause you cant use two sets of " in 'application' in FOR loop.
rem You can use backquote, or escape with ^, but still only one set of ", ("app lication" ok, but without parametres as files.)
rem 
rem This assumes exe has not spaces in it's name.
rem "app lication" ok, "app lication" "first file" not
rem
rem IF %%G==codec_name ... if TRUE, pay attention to the rest of the line, else ignore it. Without it, last variable name would not be codec_name, and mp3 will be set to encode.
rem 
rem 
rem "(set %%G=%%H)" part just assings width value to variable "width", height to height variable, etc.
rem It looks like this: ID_VIDEO_HEIGHT=640. So %%G becomes variable named ID_VIDEO_HEIGHT, with value 640. :) You can assign ID_VIDEO_HEIGHT to something like oldwidth=ID_VIDEO_HEIGHT. Oldwidth will have value 640.
rem Also you dont have to go through the output again.
rem
rem & in bat file means "newline"
rem & after IF does not work. if IF condition is not met, everything after condition is ignored :) (till the end of line)
rem for mencoder its  own resize calculator is used, even if height is calculated here.


<comment>
Resize width if greater than 512. If not in mp3, encode audio to mp2.
This one uses mencoder for encoding. Faster, but sometimes out of sync, or unfinished.
Audio will always be encoded on (.flv) files
Log length of source and destination video.
Mencoder sometimes crashes without eror. Check the log file for length of both videos.
You can also add subtitles. You need to expand program window. Button on lower right.
For flv, you might need to encode audio, or use -fps. Use DO_INFO to find framerate.

-Use DO_INFO to find the frames per second (fps) of the flv video file. Look for "framerate" value.
-Use option "-fps 25 " to set output fps to a specific value.
-This can help if you get a lot of duplicate frames.

